|2010 DIM LABLINFO%(5,20),LABLDESC$(20),YA$(|12),YA%(|12,2),ZS9(|13,1),YT$(|35),HEADER$(|35),TRAILER$(|35),PRTROW$(5,20),YT%(|35,8),YR$(|35)
*23 |2015 DIM YH%(|02,|04),YE%(|02,|04) 'Keep track of first and last Detail record numbers
2020 ON ERROR GOTO 2060:OPEN "LABLSIZE.TYP" FOR INPUT AS #ZQ+1
2030 L$="":WHILE LEFT$(L$,1)<>"*":LINE INPUT #ZQ+1, L$:WEND 'look for the * after the instructions in LABLSIZE.TYP
2040 NUMLABL%=0:WHILE NOT EOF(ZQ+1):NUMLABL%=NUMLABL%+1:INPUT #ZQ+1, LABLINFO%(1,NUMLABL%),LABLINFO%(2,NUMLABL%),LABLINFO%(3,NUMLABL%),LABLINFO%(4,NUMLABL%),LABLINFO%(5,NUMLABL%),LABLDESC$(NUMLABL%):WEND
2050 CLOSE ZQ+1:GOTO 2100
2060 E=ERR:RESUME 2080
2080 CLS:IF E=53 THEN PRINT "The LABLSIZE.TYP file is missing from the DOS default drive." ELSE IF E=62 THEN PRINT "The * just ahead of the data lines has been removed from LABLSIZE.TYP file." ELSE PRINT "BASIC Error=";E;". See your BASIC Manual"
2090 PRINT "Strike any key to end the program . . .":A$=INPUT$(1):GOTO 400
2100 CLS
2110 LOCATE 1,18,0:COLOR COLA%(2),COLA%(1)
2120 PRINT "PDS*BASE Data Base Label Printing Program";:COLOR 7,0
|2130 ZPASS=1:ZF$="|15":ZA=|16
2140 ON ERROR GOTO 2190
2150 LOCATE 3,19:COLOR COLA%(2),0:PRINT "Reading sort keys from file ";ZF$;:COLOR 7,0::OPEN ZF$ FOR INPUT AS ZQ+1:IF ZPASS=1 THEN INPUT #ZQ+1, ZTDATE$,ZTTIME$:INPUT #ZQ+1, Z5
|2160 IF ZPASS=1 THEN IF Z5<>ZS%(|16,6) THEN BEEP:LOCATE 4,2:COLOR 0,COLA%(4):PRINT "The number of records in the key file doesn't = Number of records in data base";:COLOR 7,0:CLOSE #ZQ+1:FOR X=1 TO 1000:NEXT:GOTO 2210
2170 IF ZPASS=1 THEN IF ZDATE$(ZA)<>ZTDATE$ OR ZTIME$(ZA)<>ZTTIME$ THEN BEEP:LOCATE 4,7:COLOR 0,COLA%(4):PRINT "Date & Time for the key file doesn't=Date & Time in the data base";:COLOR 7,0:CLOSE #ZQ+1:FOR X=1 TO 1000:NEXT:GOTO 2210
2180 ON ERROR GOTO 0:GOTO 2220
2190 RESUME 2200
*39 2200 IF ZPASS=2 THEN 2210 ELSE ZF$=CHR$(ZT%(ZA,1,3)+64)+":"+LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT":ZPASS=2:GOTO 2150
*40 2200 IF ZPASS=2 THEN 2210 ELSE ZF$=LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT":ZPASS=2:GOTO 2150
*41 2205 RESUME 2210
*42 2210 ON ERROR GOTO 0:CLOSE #ZQ+1:GOTO 2250
*41 2210 LOCATE 5,8:PRINT "The sort key file can not be used - Run the sort program again.":LOCATE 6,20,1:PRINT "Strike any key to end the program . . .":a$=input$(1):GOTO 400
*42 2220 ZZ5=0 'read the sort key file
*42 2230 WHILE NOT EOF(ZQ+1):ZZ5=ZZ5+1:INPUT #ZQ+1, YA%(ZZ5,2):WEND 'read the live record numbers
*42 2240 CLOSE #ZQ+1:IF ZZ5=ZS%(ZA,6) THEN IF ZPASS=1 THEN GOTO 2500 'the number of records in the sort key file may be larger if a master was deleted and re-created in the same dated session
*42 |2250 LOCATE 5,11:COLOR COLA%(2),0:PRINT "The data base must be re-sorted from the '";ZS$(|16,1);"' file.";:COLOR 7,0:Z5=0:ZA=|16
*42 2260 ZJJ=ZS%(ZA,2):IF ZPASS=2 AND ZZ5=ZS%(ZA,6) THEN ZJJ=ZZ5
*42 2270 FOR ZJ=1 TO ZJJ
*42 2280 IF ZZ5=ZS%(ZA,6) AND ZPASS=2 THEN ZR=YA%(ZJ,2) ELSE ZR=ZJ
*42 2290 ZZ=1:GOSUB 610
*42 |2300 IF ZL$<>STRING$(ZSIZE%(|16,|17),32) THEN Z5=Z5+1:YA$(Z5)=|22:YA%(Z5,1)=Z5:YA%(Z5,2)=ZR:LOCATE 6,25:PRINT ZR,ZL$;
*42 2310 NEXT 'ZJ
*42 |2320 ZREPTFLAG=0:IF Z5<> ZS%(|16,6) THEN ZS%(|16,6)=Z5:ZREPTFLAG=1 ' correct records assigned and set flags to correct the housekeeping record on closing the data base.
*42 2330 SOUND 400,1:LOCATE 7,20:COLOR COLA%(2),0:PRINT "There will be a file sort delay.";:COLOR 7,0:T%=INT((80-LEN(YA$(1)))/2)
*42 2460 OPEN ZF$ FOR OUTPUT AS ZQ+1:IF ZPASS=1 THEN WRITE #ZQ+1,ZDATE$(ZA);ZTIME$(ZA):PRINT #ZQ+1,Z5
*42 2470 FOR ZI=1 TO Z5:PRINT #ZQ+1,YA%(ZI,2):NEXT 'ZI
*42 2480 CLOSE #ZQ+1
*39 2490 IF ZPASS=2 THEN 2500 ELSE ZF$=CHR$(ZT%(ZA,1,3)+64)+":"+LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT":ZPASS=2:GOTO 2460
*40 2490 IF ZPASS=2 THEN 2500 ELSE ZF$=LEFT$(ZS$(ZA,1),(LEN(ZS$(ZA,1))-4))+".SRT":ZPASS=2:GOTO 2460
2500 '****** Select The Label Stock ******
2510 PRTDESC$=STRING$(30,32)
2520 LOCATE 10,10
2530 COLOR COLA%(2),0
2540 PRINT"Enter Label Type Number";
|2550 STOCKNUMBER%=|33
2560 FLD$=" "
2570 TYPELOOP%=1
2580 WHILE TYPELOOP%=1
2590 LOCATE 24,7,0
2600 COLOR 15,0
2610 PRINT "Enter the Label Stock Number or press Space Bar to toggle choices";
2620 COLOR 7,0
2630 LSET FLD$=MID$(STR$(STOCKNUMBER%),2)
2640 LSET PRTDESC$=LABLDESC$(STOCKNUMBER%)
2650 COLOR 0,COLA%(3)
2660 LOCATE 10,34
2670 PRINT FLD$;
2680 LOCATE 10,37
2690 COLOR COLA%(2),COLB%(1)
2700 PRINT PRTDESC$;
2710 LOCATE 10,34,1
2720 COLOR 0,COLA%(3)
2730 C$=""
2740 C1LOOP%=1
2750 WHILE C1LOOP%=1
2760 C1$=""
2770 WHILE C1$=""
2780 C1$=INKEY$
2790 WEND
2800 IF ASC(C1$)=32 THEN STOCKNUMBER%=STOCKNUMBER%+1:C1LOOP%=2:IF STOCKNUMBER% > NUMLABL% THEN STOCKNUMBER%=1
2810 IF ASC(C1$) = 13 THEN TYPELOOP%=0:C1LOOP%=0
2820 IF (ASC(C1$) < 48 OR ASC(C1$) > 57) AND C1LOOP%=1 THEN BEEP ELSE IF C1LOOP%=1 THEN PRINT C1$;:C1LOOP%=0:C$=C1$
2830 WEND
2840 C2LOOP%=1
2850 WHILE C1LOOP%=0 AND C2LOOP%=1 AND TYPELOOP%=1
2860 C2$=""
2870 WHILE C2$=""
2880 C2$=INKEY$
2890 WEND
2900 IF ASC(C2$)=32 THEN STOCKNUMBER%=STOCKNUMBER%+1:IF STOCKNUMBER% > NUMLABL% THEN STOCKNUMBER%=1
2910 IF ASC(C2$) = 13 THEN TYPELOOP%=0:C2LOOP%=0
2920 IF (ASC(C2$) < 48 OR ASC(C2$) > 57) AND C2LOOP%=1 THEN BEEP ELSE PRINT C2$;:C$=C$+C2$:C2LOOP%=0
2930 WEND
2940 COLOR 7,0:IF VAL(C$) > 0 THEN STOCKNUMBER%=VAL(C$)
2950 IF STOCKNUMBER%>NUMLABL% OR STOCKNUMBER%<1 THEN LOCATE 23,1,0:PRINT SPC(79):BEEP:LOCATE 24,18,0:PRINT "Label Stock Number must be between 1 and"+STR$(NUMLABL%);:TYPELOOP%=1
2955 IF STOCKNUMBER%>NUMLABL% OR STOCKNUMBER%<1 THEN LOCATE 24,26:PRINT "Strike any key to continue";:A$=INPUT$(1):LOCATE 23,1:PRINT SPC(79):LOCATE 24,1:PRINT SPC(79):STOCKNUMBER%=1
3100 LOCATE 12,12,0:PRINT "Turn on the printer - Strike (gently) any key when ready";:A$=INPUT$(1)
|3110 FOR ZI=1 TO |35:FOR ZJ=1 TO 8:READ YT%(ZI,ZJ):NEXT:READ HEADER$(ZI),TRAILER$(ZI):NEXT ZI
3120 ' YT%(X,Y) X=Field on report, Y=1 is file number, 2=field in that file, 3=lead to file, 4=lead to field
3130 ' 5=Detail fld action code (1=1st Detail, 2=last, 3=all), 6=Associated Master if this is a Detail
3140 ' 7=Which Detail set for this Detail's Master, 8=1 If field starts new row
*44
3300 YL$="":ZA=0:FIRSTLABEL%=1
3310 WIDTH "LPT1:",254 'Set up more than 80 columns
|3320 LPRINT |26 'Turn on Near Letter Quality printing - remove this line for faster draft quality
|3330 FOR ZJ=1 TO NUMROWS%:FOR ZK=1 TO ACROSS%:PRTROW$(ZK,ZJ)=STRING$(LABLINFO%(2,STOCKNUMBER%)-2,32):NEXT:NEXT:FOR ZJ=1 TO |35:YT$(ZJ)=STRING$(LABLINFO%(2,STOCKNUMBER%)-2,32):NEXT:ACROSSPOS%=0
3340 FOR ZI=1 TO Z5 'loop for each record in the sort file
3350 YF=0:MOREDETAIL%=0:YJ=1:LABLSKIP%=0
|3360 FOR ZJ=YJ TO |35 'loop for each field in the Label
3370 IF ZJ=1 THEN ZZ=1:ZA=YT%(1,1):ZR=YA%(ZI,2):GOSUB 610:LSET YT$(1)=Y$(YT%(1,2),ZA):GOTO 3420 'read the record for the first field
*47 3380 IF ZS%(YT%(ZJ,1),1)=2 GOTO 3440
3390 IF ZA=YT%(ZJ,1) THEN LSET YT$(ZJ)=Y$(YT%(ZJ,2),ZA):GOTO 3580 'additional field in the same master
3400 IF ZA<>YT%(ZJ,1) AND ZS%(YT%(ZJ,1),1)=1 AND YR$(ZJ)=STRING$(YT%(ZJ,4),32) THEN GOTO 3580 'skip the new field if the field leading to it was blank
3410 IF ZA<>YT%(ZJ,1) AND ZS%(YT%(ZJ,1),1)=1 THEN ZA=YT%(ZJ,1):ZR$=YR$(ZJ):GOSUB 500:GOSUB 600:LSET YT$(ZJ)=Y$(YT%(ZJ,2),ZA) 'field in a different master
*47 3420 IF ZS%(ZA,4)>0 THEN FOR ZK=1 TO ZS%(ZA,4):YH%(ZA,ZK)=ZH(ZK):YE%(ZA,ZK)=ZE(ZK):NEXT 'ZK store the chain head and ends for this master record
*48 3420 REM continuation line - do not remove
*58
*47 3430 GOTO 3540
*47 3440 'handle the detail record DO NOT remove this REM line
*47 3450 IF YT%(ZJ,1) = YT%(ZJ-1,1) THEN GOTO 3540
*47 3460 ZR=0:ZA=YT%(ZJ,1)
*47 3470 IF YF>0 THEN ZR=YF:GOTO 3500
*47 3480 IF YT%(ZJ,5)<>2 THEN ZR=YH%(YT%(ZJ,6),YT%(ZJ,7))
*47 3490 IF YT%(ZJ,5)=2 THEN ZR=YE%(YT%(ZJ,6),YT%(ZJ,7))
*47 3500 IF ZR>0 THEN ZZ=1:GOSUB 610 'read the 1st, last or next detail record
*47 3510 IF ZR=0 GOTO 3580
*47 3520 IF YT%(ZJ,5)=3 AND ZF>0 THEN MOREDETAIL%=1
*47 3530 IF MOREDETAIL%=1 THEN IF ZF>0 THEN YJ=ZJ:YF=ZF ELSE YF=0 'set up to read additional details
*47 3540 IF YT%(ZJ,5)<>999 THEN LSET YT$(ZJ)=Y$(YT%(ZJ,2),ZA)
|3550 FOR Z1=1 TO |35:IF ZA=YT%(Z1,3) THEN YR$(Z1)=Y$(YT%(Z1,4),ZA) 'set up future field search value
3560 NEXT 'Z1
3580 NEXT 'ZJ
3590 IF LABLSKIP%=0 THEN GOSUB 4000 'print Label
3600 IF YF>0 THEN GOTO 3360 'repeat for additional Details
3610 NEXT 'ZI
3620 IF ACROSSPOS%>0 THEN GOSUB 4200
|3630 LPRINT |27 'Turn off Near Letter Quality printing - remove this line if if you removed LINE 2595
4030 IF YT%(J,8)=1 THEN ROWCOLUMN%=1:IF SKIP%=0 THEN ROW%=ROW%+1
4040 SKIP%=0:FLDLEN%=LEN(YT$(J)):IF YT$(J)=STRING$(FLDLEN%,32) THEN SKIP%=1:GOTO 4100 ELSE IF RIGHT$(YT$(J),1)<>" " THEN GOTO 4070 ' field is full
4050 FOR K=FLDLEN% TO 1 STEP -1:IF MID$(YT$(J),K,1)<>" " THEN FLDLEN%=K:K=1
4060 NEXT 'K
4070 MID$(PRTROW$(ACROSSPOS%,ROW%),ROWCOLUMN%,LEN(HEADER$(J)))=HEADER$(J):ROWCOLUMN%=ROWCOLUMN%+LEN(HEADER$(J)) 'moves the header into PRTROW$
4080 MID$(PRTROW$(ACROSSPOS%,ROW%),ROWCOLUMN%,FLDLEN%)=LEFT$(YT$(J),FLDLEN%):ROWCOLUMN%=ROWCOLUMN%+FLDLEN% 'moves the field into PRTROW$
4090 MID$(PRTROW$(ACROSSPOS%,ROW%),ROWCOLUMN%,LEN(TRAILER$(J)))=TRAILER$(J):ROWCOLUMN%=ROWCOLUMN%+LEN(TRAILER$(J)) 'moves trailer into PRTROW$
4100 NEXT 'J
4110 IF ACROSSPOS%=ACROSS% THEN GOSUB 4200
4120 RETURN
4200 'Subroutine to print the labels
4210 FOR J=1 TO ROW%
4220 PRTAB%=1
4230 FOR K=1 TO ACROSS%
4240 IF K>1 THEN PRTAB%=((K-1)*ACROSSTAB%)
4250 LPRINT TAB(PRTAB%);PRTROW$(K,J);
4260 NEXT:LPRINT:NEXT
4270 FOR J=ROW%+1 TO NUMROWS%
4280 LPRINT
4290 NEXT 'J
4300 WHILE FIRSTLABEL%=1
4310 SOUND 400,1:LOCATE 14,26,0:COLOR 15,0:PRINT "Is the label lined up Ok? ";:COLOR 0,COLA%(3):PRINT "Y";:LOCATE ,POS(0)-1,1:A$="":WHILE A$="":A$=INKEY$:WEND:IF ASC(A$)=13 THEN A$="Y"
4320 PRINT A$;:COLOR 7,0
4330 IF A$="N" OR A$="n" THEN FOR J=1 TO 200:NEXT:LOCATE 14,1:PRINT SPC(79):LOCATE 12,1:PRINT SPC(79):SOUND 400,1:LOCATE 12,12,0:PRINT "Turn on the printer - Strike (gently) any key when ready";:A$=INPUT$(1):GOTO 4210
4340 FIRSTLABEL%=0
4350 WEND
4360 ACROSSPOS%=0:FOR J=1 TO NUMROWS%:FOR K=1 TO ACROSS%:LSET PRTROW$(K,J)=" ":NEXT:NEXT:RETURN 'LSET is used to reuse memory locations and prevent garbage collection